package codeblock;

/**
 * @description:
 * @Author yyp
 * @time
 */
public class CodeBlockDetail02 {
    public static void main(String[] args) {
        //静态代码块
        System.out.println("只有静态");
        A a = new A();
        //非静态代码块
        System.out.println("只有非静态");
        B b = new B();
        //静态+非静态
        System.out.println("静态+非静态");
        C c = new C();
    }
}

class A{
    private static int n1 = getN1();
    static {
        System.out.println("A静态代码块");
        System.out.println(n1);
    }

    public static int getN1(){
        System.out.println("getn1被调用");
        return 10;
    }
}
class B{
    private int n2 = getN2();
    {
        System.out.println("b非静态代码块");
        System.out.println(n2);
    }

    public int getN2(){
        System.out.println("getn2被调用");
        return 10;
    }
}

class C{
    private int n3 = getN3();
    {
        System.out.println("C非静态代码块");
    }
    static {
        System.out.println("C静态代码块");
    }

    public static int getN3(){
        System.out.println("static getn3被调用");
        return 10;
    }
}
